import { loginRSA } from '/@/config'
import { encryptedData } from '/@/utils/encrypt'
import request from '/@/utils/request'

export async function login(data: object) {
  if (loginRSA) {
    data = { ...data, password: await encryptedData(data) }
  }
  const res = request({
    url: '/login/login',
    method: 'post',
    data,
  })
  console.log(res)
  return res
}

export async function loginjk(data: object) {
  if (loginRSA) {
    data = { ...data, password: await encryptedData(data) }
  }
  return request({
    url: '/login/loginjk',
    method: 'post',
    data,
  })
}

export function getUserInfo() {
  const userinfo = request({
    url: '/login/getUserInfo',
    method: 'get',
  })
  console.log(userinfo)
  return userinfo
}

//修改密码
export function update_password(old_pwd: any, new_pwd: any) {
  return request({
    url: '/account/update_password',
    method: 'post',
    data: {
      old_password: old_pwd,
      new_password: new_pwd,
    },
  })
}
export function clear_cache() {
  const res = request({
    url: 'login/clear_cache',
    method: 'get',
  })
  console.log('clear_cache', res)
  return res
}

export function logout() {
  return request({
    url: '/login/logout',
    method: 'get',
  })
}

export function register(data: any) {
  return request({
    url: '/login/register',
    method: 'post',
    data,
  })
}
